package com.rock.platform.entity;

import javax.persistence.Entity;
import javax.persistence.Id;

import com.rock.platform.exception.BaseException;

@SuppressWarnings("serial")
@Entity
public class BaseTreeEntity extends BaseEntity
{
    @Id
    protected String id;
    protected String code;
    protected String name;
    protected String text;
    protected boolean leaf;
    
    public String getId()
    {
        return id;
    }
    
    public void setId(String id)
    {
        this.id = id;
    }
    
    public String getCode()
    {
        return code;
    }
    
    public void setCode(String code)
    {
        this.code = code;
    }
    
    public String getName()
    {
        return name;
    }
    
    public void setName(String name)
    {
        this.name = name;
    }
    
    public String getText()
    {
        return text;
    }
    
    public void setText(String text)
    {
        this.text = text;
    }
    
    public boolean getLeaf()
    {
        return leaf;
    }
    
    public <T> void setLeaf(T leaf)
    {
        if (leaf instanceof Boolean)
            this.leaf = (Boolean)leaf;
        else if (leaf instanceof Integer)
            this.leaf = ((Integer)leaf) == 1 ? true : false;
        else if (leaf instanceof String)
            this.leaf = ("1".equals(((String)leaf).trim())) ? true : false;
        else
            throw new BaseException("参数错误，leaf类型不支持："+ leaf.getClass().getName());
    }        
}
